// domain/model/BorrowRecord.java
package com.library.bookservice.domain.model;

import java.time.LocalDateTime;

/**
 * 借阅记录领域实体
 * 记录图书借阅和归还的详细信息
 */
public class BorrowRecord {
    private Long id;
    private Long bookId;
    private String borrowerName;
    private String borrowerPhone;
    private LocalDateTime borrowDate;
    private LocalDateTime returnDate;
    private boolean returned;

    // 默认构造函数
    public BorrowRecord() {}

    /**
     * 创建借阅记录的构造函数
     * @param bookId 图书ID
     * @param borrowerName 借阅人姓名
     * @param borrowerPhone 借阅人电话
     */
    public BorrowRecord(Long bookId, String borrowerName, String borrowerPhone) {
        this.bookId = bookId;
        this.borrowerName = borrowerName;
        this.borrowerPhone = borrowerPhone;
        this.borrowDate = LocalDateTime.now();
        this.returned = false;
    }

    /**
     * 标记为已归还
     * 设置归还日期和状态
     */
    public void markAsReturned() {
        if (this.returned) {
            throw new IllegalStateException("图书已归还");
        }
        this.returnDate = LocalDateTime.now();
        this.returned = true;
    }

    // Getter和Setter方法
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

    public Long getBookId() { return bookId; }
    public void setBookId(Long bookId) { this.bookId = bookId; }

    public String getBorrowerName() { return borrowerName; }
    public void setBorrowerName(String borrowerName) { this.borrowerName = borrowerName; }

    public String getBorrowerPhone() { return borrowerPhone; }
    public void setBorrowerPhone(String borrowerPhone) { this.borrowerPhone = borrowerPhone; }

    public LocalDateTime getBorrowDate() { return borrowDate; }
    public void setBorrowDate(LocalDateTime borrowDate) { this.borrowDate = borrowDate; }

    public LocalDateTime getReturnDate() { return returnDate; }
    public void setReturnDate(LocalDateTime returnDate) { this.returnDate = returnDate; }

    public boolean isReturned() { return returned; }
    public void setReturned(boolean returned) { this.returned = returned; }
}